<!--
 * @Descripttion: 
 * @Version: 1.0
 * @Author: wcl
 * @Date: 2023-11-21 16:54:39
 * @LastEditors: wcl
 * @LastEditTime: 2023-11-24 13:42:28
-->
<template>
  <div class="container">
    <a-space direction="vertical" style="width: 100%" :size="16">
      <a-card style="width: 100%" title="热销品牌配置">
        <a-form :model="formState">
          <a-row :gutter="24">
            <a-col :span="6">
              <a-form-item label="类目名称">
                <a-input
                  style="width: 100%"
                  v-model:value="formState.typeName"
                  placeholder="输入类目名称"
                />
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item label="品牌名称">
                <a-input
                  style="width: 100%"
                  v-model:value="formState.name"
                  placeholder="输入品牌名称"
                />
              </a-form-item>
            </a-col>
          </a-row>
        </a-form>

        <div class="layout-flexSpace">
          <a-space wrap>
            <a-button type="primary" @click="handleSearch">查询</a-button>
            <a-button @click="handleReset">重置</a-button>
          </a-space>
        </div>
      </a-card>

      <a-card>
        <a-table
          :dataSource="dataSource"
          :columns="paramsColumns"
          :pagination="pagination"
          @change="handleChangeSize"
        >
          <template #bodyCell="{ column, record }">
            <template v-if="column.key === 'operate'">
              <a-space>
                <a-button type="primary" @click="handelEdit(record)"
                  >编辑</a-button
                >
              </a-space>
            </template>
          </template>
        </a-table>
      </a-card>
    </a-space>
    <hotCakes ref="hotCakesRef" @refreshList="refreshList" />
  </div>
</template>
<script setup>
import { ref, onMounted } from "vue";
import { paramsColumns } from "./columns.js";
import hotCakes from "./categoryModule/hotCakes.vue";
import { getHotBrandList } from "@/api/goodConfig.js";

const pagination = ref({
  current: 1,
  pageSize: 10,
  defaultPageSize: 10,
  total: 0,
  showSizeChanger: true,
  pageSizeOptions: ["10", "20", "50", "100"],
  showTotal: (total) => `共 ${total} 条`,
});
const formState = ref({
  page: pagination.value.current,
  pageSize: pagination.value.pageSize,
  typeName: undefined,
  name: undefined,
});
const hotCakesRef = ref(null);
const dataSource = ref([]);
const getTypeBrandList = () => {
    getHotBrandList(formState.value).then((res) => {
    dataSource.value = res.data.list;
    pagination.value.total = res.data.total;
  });
};
function handleSearch() {
  formState.value.page = 1
  formState.value.pageSize = 10
  getTypeBrandList();
}
function refreshList() {
    getTypeBrandList();
}
const handelEdit = (record) => {
  hotCakesRef.value.open(record);
};

function handleReset() {
  formState.value = {
    page: 1,
    pageSize: 10,
    categoryId: undefined,
    subCategoryId: undefined,
    searchCondition: undefined,
    status: undefined,
  };
  pagination.value.current = 1
  pagination.value.pageSize = 10
  getTypeBrandList();
}

function handleChangeSize(page) {
  formState.value.page = page.current;
  formState.value.pageSize = page.pageSize;
  pagination.value.current = page.current;
  pagination.value.pageSize = page.pageSize;
  getTypeBrandList();
}
onMounted(() => {
  getTypeBrandList();
});
</script>

<style lang="less">
.img-item {
  display: flex;
  flex-direction: column;
  align-items: center;

  .img-label {
    margin-top: 6px;
    color: #9599a5;
    font-size: 12px;
  }
}
</style>
